package demo2;

/**
 * @Author liangzai
 * @Description:
 */
public class Date {
    public int year;
    public int month;
    public int day;

    //构造方法1
    public Date(int year, int month, int day){
        this.year = year;
        this.month = month;
        this.day = day;
    }
    //构造方法2
    public Date(int year,int month){
        this.year = year;
        this.month = month;
    }
    //构造方法3
    public Date(int year,int day){
        this.year = year;
        this.day = day;
    }

    public void printDate(){
        System.out.println(year + "-" + month + "-" + day);
    }

    public static void main(String[] args) {
        // 此处创建了一个Date类型的对象，并没有显式调用构造方法
        Date d = new Date(2021,6,9);
        //构造方法的作用就是对对象中的成员进行初始化，并不负责给对象开辟空间
        d.printDate();   // 2021-6-9
    }
}

